<?php
namespace Home\Controller;

/**
 * FAQ控制器
 * @author liubo <liubo@ilongyuan.com.cn>
 */
class FaqController extends HomeController
{
    private $eventObj;
    public function _initialize() {
        parent::_initialize();
        C('DEFAULT_THEME', 'ui2');  
        $this->eventObj = event('Faq');
    }

    public function index() {
        $id = I('id', 0, 'intval');
        $this->assign('id',$id);

        $this->assign('title','FAQ');
        $this->display();
    }

    public function search() {
        $keywords = I('keywords', '', 'trim');
        $page = I('page', 1, 'intval');
        !$page && $page = 1;
        $pager = I('pager', 15, 'intval');

        $res = $this->eventObj->search($keywords, $page, $pager);
        
        $this->ajaxReturn(array('state'=>0, 'info'=>'操作成功', 'data'=>$res));
    }

    public function frequent() {
        $top = I('top', 10, 'intval');

        $res = $this->eventObj->getTop($top);
        $this->ajaxReturn(array('state'=>0, 'info'=>'操作成功', 'data'=>$res));
    }

    public function detail() {
        $id = I('id', 0, 'intval');
        if (empty($id)) {
            $this->ajaxReturn(array('state'=>-1, 'info'=>'参数错误', 'data'=>[]));
        }
        $detail = $this->eventObj->detail($id);
        $this->ajaxReturn(array('state'=>0, 'info'=>'操作成功', 'data'=>$detail));
    }

}